home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 25
/
Aminet 25 (1998)(GTI - Schatztruhe)[!][Jun 1998].iso
/
Aminet
/
dev
/
amos
/
AMOS0398.lzh
/
AMOSLIST
/
000044_amos-request@svcs1.digex.net_Thu Mar 5 05:34:10 1998.msg
< prev
next >
Wrap
Text File
|
1998-04-01
|
5KB
|
155 lines
>From amos-request@svcs1.digex.net Thu Mar 5 05:34:09 1998
Received: from svcs1.digex.net (svcs1.digex.net [204.91.197.224])
by pony-1.mail.digex.net (8.8.8/8.8.8) with ESMTP id FAA22215
for <mcox@access.digex.net>; Thu, 5 Mar 1998 05:34:09 -0500 (EST)
Received: (from daemon@localhost)
by svcs1.digex.net (8.8.5/8.8.5) id EAA20423
for amos-out; Thu, 5 Mar 1998 04:01:38 -0500 (EST)
Received: from pony-2.mail.digex.net (pony-2.mail.digex.net [204.91.241.6])
by svcs1.digex.net (8.8.5/8.8.5) with ESMTP id EAA20420
for <amos-list@svcs1.digex.net>; Thu, 5 Mar 1998 04:01:38 -0500 (EST)
Received: from mailhost.sosbbs.com (sosbbs.com [204.186.168.100])
by pony-2.mail.digex.net (8.8.8/8.8.8) with SMTP id EAA24276
for <amos-list@access.digex.net>; Thu, 5 Mar 1998 04:01:34 -0500 (EST)
Received: from default (204.186.168.51) by mailhost.sosbbs.com
(EMWAC SMTPRS 0.81) with SMTP id <B0000224869@mailhost.sosbbs.com>;
Thu, 05 Mar 1998 03:58:05 -0500
Message-ID: <B0000224869@mailhost.sosbbs.com>
From: "Garfield Benjamin" <gbenjam@sosbbs.com>
To: "AMOS MAILING LIST" <amos-list@access.digex.net>
Subject: Re: need help rotating a map!!
Date: Thu, 5 Mar 1998 04:12:01 -0500
X-MSMail-Priority: Normal
X-Priority: 3
X-Mailer: Microsoft Internet Mail 4.70.1155
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Status: O
X-Status:
> I'm making a dungeon game its levels are 50x50 stored in an array
> I need some code to rotate this map 90 degrees in either direction..
For the sake of simplicity, the code below assumes you're useing a
two-dimensional array to store your map. Obviously, a one-
dimensional array or particularly a binary array would be more
effiecient, but you can apply the design to whatever method you're
actually using...
Okay, the idea is simple enough. To rotate your map counter clock
wise, you need to transfer the map rows (top to bottom) to the map
cols (left to right)...
ABCDE EJOTY
FGHIJ DINSX
KLMNO CHMRW
PQRST BGLQV
UVWXY AFKPU
And for clockwise rotation, you simply transfer the map rows (top to
bottom) to the map cols (right to left)...
ABCDE UPKFA
FGHIJ VQLGB
KLMNO WRMHC
PQRST XSNID
UVWXY YTOJE
Of course, that is simply the way I am viewing it, you could look
at the process in a number of ways, but moving on to the code...:)
BTW- I'm on my PC and just did a quick test in C (these routines\
work fine), so if I make some syntax errors in the AMOS
version (created on the fly below), you'll know why...
I'm going to use a 5x5 matrix for this example, as my creation code
fills a 5x5 MAP with the characters in the above examples...
just change the MAPWIDTH and MAPHEIGHT values to 50.
--------<CODE STARTS HERE>--------
Dim MAP(50,100) : Rem Double-height BUFFERED map...
Shared MAP(), MAPBASE, MAPWIDTH, MAPHEIGHT
Procedure ROTATEMAPLEFT
DESTBASE=MAPHEIGHT-MAPBASE
DESTCOL=0
For REP=0 To MAPHEIGHT-1
SOURCEROW=MAPBASE+REP
DESTROW=DESTBASE+(MAPHEIGHT-1)
For SOURCECOL=0 To MAPWIDTH-1
MAP(DESTCOL,DESTROW)=MAP(SOURCECOL,SOURCEROW)
Dec DESTROW
Next SOURCECOL
Inc DESTCOL
Next REP
MAPBASE=DESTBASE
End Proc
Procedure ROTATEMAPRIGHT
DESTBASE=MAPHEIGHT-MAPBASE
DESTCOL=MAPWIDTH-1
For REP=0 To MAPHEIGHT-1
SOURCEROW=MAPBASE+REP
DESTROW=DESTBASE
For SOURCECOL=0 To MAPWIDTH-1
MAP(DESTCOL,DESTROW)=MAP(SOURCECOL,SOURCEROW)
Inc DESTROW
Next SOURCECOL
Dec DESTCOL
Next REP
MAPBASE=DESTBASE
End Proc
Procedure MAPVIEW
For YPOS=0 To MAPHEIGHT-1
Print " ";
For XPOS=0 To MAPWIDTH-1
Print Chr$(MAP(XPOS,MAPBASE+YPOS));
Next XPOS
Print
Next YPOS
End Proc
' ----------------------------
' MAIN CODE HERE
'-----------------------------
MAPBASE=0 : Rem Toggled between 0 and 5 for buffering
MAPWIDTH=5 : MAPHEIGHT=5
Print "Initializing Map..." : PRINT
TILE=Asc("A")
For YPOS=0 To MAPHEIGHT-1
For XPOS=0 To MAPWIDTH-1
MAP(XPOS,MAPBASE+YPOS)=TILE
Add TILE,1,Asc("A") To Asc("Z")
Next XPOS
Next YPOS
Print "Map defined as follows:"
MAPVIEW
Print "Original Map rotated CounterClockWise:"
ROTATEMAPLEFT
MAPVIEW
Print "Original Map rotated ClockWise:"
ROTATEMAPRIGHT : ROTATEMAPRIGHT
MAPVIEW
Wait Key
End
--------<CODE ENDS HERE>--------
Everytime you call these rotation functions, the MAPBASE is
changed, so you'll need to use MAPBASE+ROW to access your map.
I used a buffered design as this is faster than having to copy your
MAP into a temporary workbuffer then rotate "back" to the MAP
array...
Anyway, hope this helps... :-)
Garfield Benjamin e-mail:gbenjam@sosbbs.com
VerticalShooter(PC): 52% complete(...23 days)
NEW!! (DemoVersion0.52 available on my GAMES-page) NEW!!
Website( http://www.sosbbs.com/~gbenjam ): 50% Complete